﻿<ribbon:RibbonWindow x:Class="MainWindow"
                     x:Name="window"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:view="clr-namespace:RegExUtility.View"
                     xmlns:viewModel="clr-namespace:RegExUtility.ViewModel;assembly=RegexUtility.ViewModel"
                     xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
                     Title="RegEx Utility Alpha"
                     DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ViewModel}"
                     Height="600"
                     Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <ribbon:Ribbon>
            <ribbon:Ribbon.ApplicationMenu>
                <ribbon:RibbonApplicationMenu>
                    <ribbon:RibbonApplicationMenuItem Header="Open"
                                                      Command="{Binding Path=Commands[Open]}">

                    </ribbon:RibbonApplicationMenuItem>
                    <ribbon:RibbonApplicationMenuItem Header="Save"
                                                      Command="{Binding Path=Commands[Save]}">

                    </ribbon:RibbonApplicationMenuItem>
                    <ribbon:RibbonSeparator />
                    <ribbon:RibbonApplicationMenuItem Header="Exit"
                                                      Command="{Binding Path=Commands[Exit]}">

                    </ribbon:RibbonApplicationMenuItem>
                </ribbon:RibbonApplicationMenu>
            </ribbon:Ribbon.ApplicationMenu>
            <ribbon:RibbonTab Header="RegEx Options">
                <ribbon:RibbonGroup Header="ECMA-Compliant Options">
                    <ribbon:RibbonGroup.GroupSizeDefinitions>
                        <ribbon:RibbonGroupSizeDefinition>
                            <ribbon:RibbonControlSizeDefinition ImageSize="Large" />
                        </ribbon:RibbonGroupSizeDefinition>
                    </ribbon:RibbonGroup.GroupSizeDefinitions>

                    <ribbon:RibbonCheckBox Label="ECMA Script"
                                           IsChecked="{Binding IsRegexECMAScriptEnabled}"
                                           ToolTipTitle="ECMAScript"
                                           ToolTipDescription="Enables ECMAScript-compliant behavior for the expression. This value can be used only in conjunction with the IgnoreCase, Multiline, and Compiled values. The use of this value with any other values results in an exception.&#10;&#10;(Most versions of JavaScript use the ECMA-262 standard, and VBA uses the ECMAScript standard with some exceptions.)"
                                           LargeImageSource="Resources/Images/globe.png" />

                    <ribbon:RibbonCheckBox Label="Ignore Case"
                                           IsChecked="{Binding IsRegexIgnoreCaseEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Specifies case-insensitive matching."
                                           ToolTipFooterDescription="/abc/ = abc, Abc, ABC"
                                           SmallImageSource="Resources/Images/Aa.png" />
                    <ribbon:RibbonCheckBox Label="Multiline"
                                           IsChecked="{Binding IsRegexMultilineEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Multiline mode. Changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string."
                                           SmallImageSource="Resources/Images/multiline.png" />
                    <ribbon:RibbonCheckBox Label="Compiled"
                                           IsChecked="{Binding IsRegexCompiledEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Specifies that the regular expression is compiled to an assembly. This yields faster execution but increases startup time. This value should not be assigned to the Options property when calling the CompileToAssembly method."
                                           SmallImageSource="Resources/Images/compile.png" />
                </ribbon:RibbonGroup>
                <ribbon:RibbonGroup Header="Non-ECMA-Compliant Options">
                    <ribbon:RibbonGroup.Resources>
                        <Style TargetType="ribbon:RibbonCheckBox">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsRegexECMAScriptEnabled}"
                                             Value="True">
                                    <Setter Property="IsEnabled"
                                            Value="False" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ribbon:RibbonGroup.Resources>
                    <ribbon:RibbonCheckBox Label="Explicit Capture"
                                           IsChecked="{Binding IsRegexExplicitCaptureEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Specifies that the only valid captures are explicitly named or numbered groups of the form (?&lt;name>...). This allows unnamed parentheses to act as noncapturing groups without the syntactic clumsiness of the expression (?:…)."
                                           ToolTipFooterDescription="/(?&lt;GroupName>.*)/" />
                    <ribbon:RibbonCheckBox Label="Singleline"
                                           IsChecked="{Binding IsRegexSinglelineEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n)." />
                    <ribbon:RibbonCheckBox Label="Ignore Pattern Whitespace"
                                           IsChecked="{Binding IsRegexIgnorePatternWhitespaceEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Eliminates unescaped white space from the pattern and enables comments marked with #. However, the IgnorePatternWhitespace value does not affect or eliminate white space in character classes."
                                           ToolTipFooterDescription="/abc # Simple search for 'abc'/ = abc" />
                    <ribbon:RibbonCheckBox Label="Right-To-Left"
                                           IsChecked="{Binding IsRegexRightToLeftEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Specifies that the search will be from right to left instead of from left to right." />
                    <ribbon:RibbonCheckBox Label="Culture Invariant"
                                           IsChecked="{Binding IsRegexCultureInvariantEnabled}"
                                           ToolTipTitle="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Label}"
                                           ToolTipDescription="Specifies that cultural differences in language is ignored. See Performing Culture-Insensitive Operations in the RegularExpressions Namespace for more information." />
                </ribbon:RibbonGroup>
            </ribbon:RibbonTab>
        </ribbon:Ribbon>

        <Grid Grid.Row="1"
              Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Grid Margin="0,0,0,8">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <Label Content="Pattern" />

                <TextBox Text="{Binding RegexPattern, UpdateSourceTrigger=PropertyChanged}"
                         Grid.Row="1"
                         VerticalAlignment="Top"
                         VerticalScrollBarVisibility="Auto"
                         HorizontalScrollBarVisibility="Auto">
                    <TextBox.Style>
                        <Style TargetType="TextBox">
                            <Setter Property="Height"
                                    Value="22" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=MultilinePatternCheckBox, Path=IsChecked}"
                                             Value="True">
                                    <Setter Property="Height"
                                            Value="90" />
                                    <Setter Property="TextWrapping"
                                            Value="NoWrap" />
                                    <Setter Property="AcceptsReturn"
                                            Value="True" />
                                    <Setter Property="AcceptsTab"
                                            Value="True" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBox.Style>
                </TextBox>

                <ToggleButton Name="FormatRegexToggleButton"
                              Grid.Column="1"
                              Grid.Row="1">
                    <ToggleButton.Template>
                        <ControlTemplate TargetType="ToggleButton">
                            <Image Source="Resources/Images/paste.png"
                                   Height="21" />
                        </ControlTemplate>
                    </ToggleButton.Template>
                </ToggleButton>

                <Popup IsOpen="{Binding ElementName=FormatRegexToggleButton, Path=IsChecked, FallbackValue=False}"
                       Visibility="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsOpen, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"
                       PlacementTarget="{Binding ElementName=FormatRegexToggleButton}"
                       Placement="Right"
                       AllowsTransparency="True"
                       StaysOpen="False">
                    <Border Background="White"
                            BorderBrush="#FFCCF0FF"
                            BorderThickness="1"
                            Padding="8"
                            SnapsToDevicePixels="True">
                        <StackPanel>
                            <Button Content="As C# Code..."
                                    Command="{Binding Path=Commands[FormatRegex]}"
                                    CommandParameter="CSharp"
                                    Style="{StaticResource ResourceKey=HyperlinkButtonStyle}" />
                            <Button Content="As VB Code..."
                                    Command="{Binding Path=Commands[FormatRegex]}"
                                    CommandParameter="VB"
                                    Style="{StaticResource ResourceKey=HyperlinkButtonStyle}" />
                        </StackPanel>
                    </Border>
                </Popup>

                <ToggleButton Content="View Pattern History"
                              Name="PatternHistoryToggleButton"
                              Grid.Row="2"
                              VerticalAlignment="Top"
                              HorizontalAlignment="Left" />

                <Popup IsOpen="{Binding ElementName=PatternHistoryToggleButton, Path=IsChecked, FallbackValue=False}"
                       Visibility="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsOpen, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"
                       PlacementTarget="{Binding ElementName=PatternHistoryButton}"
                       Placement="Bottom"
                       StaysOpen="False"
                       MinWidth="300"
                       MinHeight="200">
                    <ListView ItemsSource="{Binding RegexHistory}"
                              DisplayMemberPath="Item1">

                    </ListView>
                </Popup>

                <CheckBox x:Name="MultilinePatternCheckBox"
                          Grid.Row="2"
                          HorizontalAlignment="Right"
                          Content="Multiline Pattern" />
            </Grid>

            <Grid Grid.Row="1">
                <TabControl ItemsSource="{Binding InputViewModels}"
                            SelectedItem="{Binding SelectedInputViewModel}">
                    <TabControl.ItemContainerStyle>
                        <Style TargetType="TabItem">
                            <Setter Property="Header"
                                    Value="{Binding HeaderText}" />
                            <Setter Property="Content"
                                    Value="{Binding }" />
                        </Style>
                    </TabControl.ItemContainerStyle>
                </TabControl>
            </Grid>

        </Grid>

        <Border Grid.RowSpan="2"
                Background="#30000000"
                Visibility="{Binding Path=IsLongProcessRunning, ElementName=window, Converter={StaticResource BooleanToVisibilityConverter}}">

            <StackPanel HorizontalAlignment="Stretch"
                        VerticalAlignment="Center"
                        Margin="16,0">
                <ProgressBar Value="{Binding Path=LongProcessProgress, ElementName=window}"
                             Height="30" />
                <ContentControl Margin="0,8,0,0"
                                Content="{Binding Path=LongProcessUserState, ElementName=window}" />
            </StackPanel>

        </Border>

    </Grid>
</ribbon:RibbonWindow>
